﻿using Autofac.Extensions.DependencyInjection;
using ECommon.Autofac;
using ECommon.Components;
using ECommon.Configurations;
using ENode.Configurations;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using System.Reflection;
using Autofac;

namespace User.API
{
    public static class ConfigurationExtensions
    {
        /// <summary>Register all the controllers into ioc container.
        /// </summary>
        /// <returns></returns>
        public static Configuration RegisterControllers(this Configuration configuration)
        {
            var containerBuilder = (ObjectContainer.Current as AutofacObjectContainer).ContainerBuilder;

            var controllerType = typeof(ControllerBase);
         
            containerBuilder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                .Where(x => controllerType.IsAssignableFrom(x) && x != controllerType)
                .PropertiesAutowired();

            return configuration;
        }


    }
}